/*
 * User: rant
 * Date: Aug 23, 2007
 *
 *
 */
package laMalinche.rete.nodes.editing;

import laMalinche.testingPlayGround.testModel.VOEntity;

import java.util.*;

/**
 *
 */
@Deprecated
public class OpenFieldCertaintyManagerInformer extends OpenFieldCertaintyManager implements FutureEditingInformer {

	public boolean willBeActive(Set<String> aboutTochange) {
		final String openField = getOpenTouchedElement();
		boolean isActive = isNotFalse();
		boolean isGoingTobeActive = falseButGoingToBeActive(aboutTochange);
		boolean isGoingToBeCertain = ((openField != null) &&
				aboutTochange.contains(openField));
		return isActive || isGoingTobeActive || isGoingToBeCertain;
	}

	public Set<String> activatedBy(Set<String> aboutTochange) {
		Set<String> activators = new HashSet<String>();
		final String element = getOpenTouchedElement();
			final Set<String> touched = touched(activators);
			if (element == null  || aboutTochange.contains(element)) {
						return touched;
			}

		return null;
	}

	private boolean falseButGoingToBeActive(final Set<String> aboutTochange) {
		boolean isGoingTobeActive = !isNotFalse() && getOpenTouchedElement() == null && !touched(aboutTochange).isEmpty();
		return isGoingTobeActive;
	}

	private boolean isNotFalse() {
		boolean isActive = getConditionNode().isConditionMet() != Boolean.FALSE;
		return isActive;
	}

	private Set<String> touched(final Set<String> aboutTochange) {
		final Set<String> touched = new HashSet<String>();
		final List<VOEntity> list = getWorkingMemory().getRelevantFields();
		for (VOEntity s : list) {
			final String field = s.getOgnl();
			if (aboutTochange.contains(field)) {
                touched.add(field);
            }
		}
		return touched;
	}
}